package com.example.pattern.guide

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
import com.example.pattern.databinding.FragmentGuide2Binding



class GuideFragment : Fragment() {
    private lateinit var binding:FragmentGuide2Binding
   override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
       binding = FragmentGuide2Binding.inflate(inflater,container,false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
       // SPUtil.defaultUtils(requireContext()).isFirst = false
       binding.viewPager.adapter = GuideAdapter(
           listOf(GuideOneFragment(),GuideTwoFragment(),GuideTreeFragment(),GuideFourFragment()),
           parentFragmentManager,
           lifecycle)
        binding.viewPager.registerOnPageChangeCallback(object :OnPageChangeCallback(){
            override fun onPageSelected(position: Int) {
                binding.indicatorView.select(position)
            }
        })
        binding.indicatorView.addPageChangeCallBack = {page ->
            if(binding.viewPager.currentItem != page){
                binding.viewPager.setCurrentItem(page,true)
            }
        }
    }
}